package com.example.gustavo.hello.activity;

import android.os.Looper;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

import com.example.gustavo.hello.R;
import com.ks.gopush.cli.GoPushCli;
import com.ks.gopush.cli.Listener;
import com.ks.gopush.cli.PushClient;
import com.ks.gopush.cli.PushMessage;

import java.util.List;

public class GoPushActivity extends ActionBarActivity {

    private ThreadLocal<GoPushCli> local = new ThreadLocal<GoPushCli>();
    private String host;
    private Integer port;
    private String key;
    private Integer heartBeat;
    private EditText et_imoj;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_go_push);

        et_imoj = (EditText) findViewById(R.id.et_imoj);

        System.out.println(45 >>> 1);
        initPush();

    }
    public void start(View view){

        PushClient.init(host, port, key, heartBeat);
    }
    public void stop(View view){

        PushClient.stop();

    }

    private void initPush() {

        //http://go.ktkt.com:8090/kt/server/get?k=2&p=2

        host = "go.ktkt.com";
        port = 8090;
        key = "stock_reslut_vip";
        heartBeat = 30;

        String[] sts = {"go.ktkt.com"
                ,"stock_reslut_vip"
        };
       /* new Thread(){
            @Override
            public void run() {

                boolean b = Looper.getMainLooper() == Looper.myLooper();
                System.out.println("isMain = " + b);

                new GoPushCli(host, port, key, heartBeat, new Listener() {
                    @Override
                    public void onOpen() {

                        System.out.println("onOpen = duang");

                    }

                    @Override
                    public void onClose() {

                        System.out.println("onClose = close");

                    }

                    @Override
                    public void onOnlineMessage(PushMessage message) {

                        System.out.println("online message = " + message.toString());
                    }

                    @Override
                    public void onOfflineMessage(List<PushMessage> messages) {

                        for (PushMessage message : messages) {

                            System.out.println("offline message = " + message.toString());
                        }
                    }

                    @Override
                    public void onError(Throwable e, String message) {

                        System.out.println("error = " + e.toString());
                        e.printStackTrace();
                    }
                }).start(false, 0, 0);


            }
        }.start();*/

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_go_push, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
